﻿namespace KeRui.URLRewriter.Form
{
    using System;
    using System.IO;
    using System.Web;
    using System.Web.UI;

    public class RewriteFormHtmlTextWriter : HtmlTextWriter
    {
        public RewriteFormHtmlTextWriter(TextWriter writer) : base(writer)
        {
            base.InnerWriter = writer;
        }

        public RewriteFormHtmlTextWriter(HtmlTextWriter writer) : base(writer)
        {
            base.InnerWriter = writer.InnerWriter;
        }

        public override void WriteAttribute(string name, string value, bool fEncode)
        {
            if (name == "action")
            {
                HttpContext current = HttpContext.Current;
                if (current.Items["ActionAlreadyWritten"] == null)
                {
                    value = current.Request.RawUrl;
                    current.Items["ActionAlreadyWritten"] = true;
                }
            }
            base.WriteAttribute(name, value, fEncode);
        }
    }
}

